<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class StatisticsAttended extends AdminController {

	function __construct() {
		parent::__construct();
		$this-> load->model('Attend_model');
		$this -> load -> model("Admin_model");
		$this -> load -> model("Class_model");
		 $this -> load ->library('ProjectService/admin_service');
	}

	function Index(){
		//按教师分类
		$connar['items']='distinct(dept_name)';
		$dept_name=$this->Admin_model->get_list_full($connar);

		//按开课单位分类
		$connar1['items']='distinct(course_units)';
		$connar1['where']='course_units is not null';

		$course_units=$this->Class_model->get_list_full($connar1);

		$data['dept_name']= $dept_name;
		$data['course_units']= $course_units;
		$this->load->view('admin/statisticsAttendedList',$data);
	}

	function getDatas($params = array(), $isExport = false){
		$connar = array();
		$params = $_POST;
		if (!$isExport) {
		
			$connar = $this -> Attend_model -> pickPages($connar, $params);
		}

        $manage=$this->admin_service->getAdminById(getSess()['id']);

 		//查询当前用户的角色
		 $sub_role=explode(',',  $manage['sub_role_id']);
         array_push($sub_role,  $manage['role_id']);

        //判断是否管理员
         if(!in_array(WebRole::Admin[XPHEnum::Value], $sub_role) && !in_array(WebRole::Manage[XPHEnum::Value], $sub_role)){

        	 //查询该用户的开课单位信息
        	$connar5['items']='distinct(course_units)';
			$connar5['where']=$this->sqlEscape('teacher_code=??',array($manage['usercode']));
			$dept_name_1=$this->Attend_model->get_single_full($connar5);

			//pri($dept_name_1);
			
			/*$connar5['items']='distinct(course_units)';
		    $connar5['where']='course_units is not null and find_in_set('.$manage['usercode'].',teacher_id)';

		   $course_units=$this->Class_model->get_single_full($connar5);*/

			//督导组长可查询本分院
	        if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role)){
	        	//$params['course_units'] = $course_units['course_units'];// $dept_name_1['course_units']?$dept_name_1['course_units']:$manage['dept_name'];
	            $params['course_units'] = $dept_name_1['course_units'];
	            $params['dept_name'] =  $manage['dept_name'];
	        } 

			//校督导,二级督导,外聘督导只能查看自己
	        if(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $sub_role) or in_array(WebRole::UnitSupervisor[XPHEnum::Value], $sub_role) or in_array(WebRole::OutsideSupervisor[XPHEnum::Value], $sub_role)){
	        		$params['teacher_code'] =  $manage['usercode'];
	        	if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $sub_role)){//督导组长查询本分院
	        		unset($params['teacher_code']);        	
	        	}
	        } 
        }     


		// 按开课单位分类
		if(isset($_POST['type']) && $_POST['type']==1){
			$connar['where']=$this->sqlEscape('db_attend.status=??',array(AttendStatus::Submit[XPHEnum::Value]));
			$where='where 1=1 ';
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar['where'].=' and db_attend.listen_time>='.strtotime($params['start_time']).' and db_attend.listen_time<='.strtotime($params['end_time'].'23:59:59');
				$where.=' and db_attend.listen_time>='.strtotime($params['start_time']).' and db_attend.listen_time<='.strtotime($params['end_time'].'23:59:59');
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');
				$where.=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');
			}	

			//课程类型
			
            if(isset($params['class_type'])&&$params['class_type']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.type=?? ",array($params['class_type']));
            }

            //分院名称
             if(isset($params['course_units'])&&$params['course_units']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.course_units=?? ",array($params['course_units']));
            }

            //二级督导，校督导，外聘督导只能查看自己
            if(isset($params['teacher_code']) &&  $params['teacher_code'] != ''){
            	  $connar['where'] .= $this->sqlEscape(" and db_attend.teacher_code=?? ",array($params['teacher_code']));
            }

			$connar['items']="group_concat(DISTINCT id) attend_id,db_attend.course_units";
			$connar['groupby']="course_units";
			$connar['orderby']='field(dept_name,"电气电子工程分院","机械工程分院","建筑工程分院","设计与艺术分院","财经分院","交通分院","商贸分院","鉴湖分院","人文社科部")';

			// if (!$isExport) {
			// 	// $data = $this -> Attend_model -> get_page_list($connar);
			// 	$data=$
			// } else {
			$count=$this->Attend_model->query('select count(*)count from (select count(*) from db_attend '.$where.' group by course_units order by field(dept_name,"电气电子工程分院","机械工程分院","建筑工程分院","设计与艺术分院","财经分院","交通分院","商贸分院","鉴湖分院","人文社科部")) count');
			$data['count']=$count[0]['count'];
			if(isset($params['pageSize'])){
				$data["totalPage"] = ceil($count[0]["count"] / $params['pageSize']);
				$data['pageNo']=$params['pageNo'];
			}else{
				$data["totalPage"] = ceil($count[0]["count"] / 20);
				$data['pageNo']=1;
			}
			
			$data["ret"] = $this -> Attend_model -> get_list_full($connar);

			foreach ($data['ret'] as $k => $v) {
    		   //        // 被听人数
				$course_units=str_replace ('学','分', $v['course_units']);
    		            // 分院督导听课人数 --本分院
				$connar2['items']='count(DISTINCT teacher_name) unitsupervisor_num';
    					// $connar2['where']=$this->sqlEscape('db_admin.dept_name=db_attend.dept_name and db_attend.dept_name=?? and type=?? and db_attend.status=??',array($v['dept_name'],AttendType::Unit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));   
				$connar2['where']=$this->sqlEscape('db_attend.dept_name=?? and db_attend.status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$unitsupervisor_num=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['unitsupervisor_num']=$unitsupervisor_num['unitsupervisor_num'];
    		            // 分院督导听课次数 
				$connar2['items']='COUNT(*) unitsupervisor_count';
    					// $connar2['where']=$this->sqlEscape('db_admin.dept_name=db_attend.dept_name and db_attend.dept_name=?? and type=?? and db_attend.status=??',array($v['dept_name'],AttendType::Unit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$connar2['where']=$this->sqlEscape('db_attend.dept_name=?? and db_attend.status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$unitsupervisor_count=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['unitsupervisor_count']=$unitsupervisor_count['unitsupervisor_count'];
    		            // 校督导听课人数  
				$connar2['items']='count(DISTINCT teacher_name) schoolsupervisor_num';
    					// $connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$v['dept_name'],AttendStatus::Submit[XPHEnum::Value]));
				$connar2['where']=$this->sqlEscape('db_attend.dept_name=?? and db_attend.status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$schoolsupervisor_num=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['schoolsupervisor_num']=$schoolsupervisor_num['schoolsupervisor_num'];
    		            // 校督导听课次数  
				$connar2['items']='COUNT(*) schoolsupervisor_count';
				$connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$schoolsupervisor_count=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['schoolsupervisor_count']=$schoolsupervisor_count['schoolsupervisor_count'];

				        // 外聘督导听课人数  
				// $connar2['items']='count(DISTINCT teacher_name) outsidesupervisor_num';
    // 					// $connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$v['dept_name'],AttendStatus::Submit[XPHEnum::Value]));
				// $connar2['where']=$this->sqlEscape('db_attend.dept_name=?? and db_attend.status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
    // 					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				// $outsidesupervisor_num=$this->Attend_model->get_single_full($connar2);
				// $data['ret'][$k]['outsidesupervisor_num']=$outsidesupervisor_num['outsidesupervisor_num'];
    // 		            // 外聘督导听课次数  
				// $connar2['items']='COUNT(*) outsidesupervisor_count';
				// $connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::Outside[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
    // 					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				// $outsidesupervisor_count=$this->Attend_model->get_single_full($connar2);
				// $data['ret'][$k]['outsidesupervisor_count']=$outsidesupervisor_count['outsidesupervisor_count'];

				// //总平均分
				// $connar1['items']='avg(score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=??',array($course_units,AttendStatus::Submit[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_total_score']=sprintf("%.2f",$avg['avg']);

				// //校督导听课总平均分
				// $connar1['items']='avg(score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_school_score']=sprintf("%.2f",$avg['avg']);

				// //二级督导听课总平均分
				// $connar1['items']='avg(score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_unit_score']=sprintf("%.2f",$avg['avg']);


				// //外督导听课总平均分
				// $connar1['items']='avg(score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=?? and type=??',array($course_units,AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_outside_score']=sprintf("%.2f",$avg['avg']);


    // 		            // 教学水平平均分          
				// $connar1['items']='avg(teaching_level_score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=??',array($course_units,AttendStatus::Submit[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_level']=sprintf("%.2f",$avg['avg']);
    // 					// 教学效果平均分          
				// $connar1['items']='avg(teaching_effect_score) avg';
				// $connar1['where']=$this->sqlEscape('dept_name=?? and status=??',array($course_units,AttendStatus::Submit[XPHEnum::Value]));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				// }
				// $avg=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['avg_effect']=sprintf("%.2f",$avg['avg']);
    // 		            // 教学水平90分(含)以上
				// $connar1['items']="count(*) as count";
				// $connar1['where']=$this->sqlEscape('teaching_level_score>=90 and status=??  and dept_name=??',array(AttendStatus::Submit[XPHEnum::Value],$course_units));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				// }
				// $abovenine=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['abovenine_level']=$abovenine['count'];			

    // 					// 教学水平80以下
				// $connar1['items']="count(*) as count";
				// $connar1['where']=$this->sqlEscape('teaching_level_score<80 and status=??  and dept_name=??',array(AttendStatus::Submit[XPHEnum::Value],$course_units));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				// }
				// $aboveeight=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['aboveeight_level']=$aboveeight['count'];

    // 					// 教学效果90分(含)以上
				// $connar1['items']="count(*) as count";
				// $connar1['where']=$this->sqlEscape('teaching_effect_score>=90 and status=??  and dept_name=??',array(AttendStatus::Submit[XPHEnum::Value],$course_units));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				// }
				// $abovenine=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['abovenine_effect']=$abovenine['count'];			

    // 					// 教学效果80以下
				// $connar1['items']="count(*) as count";
				// $connar1['where']=$this->sqlEscape('teaching_effect_score<80 and status=??  and dept_name=??',array(AttendStatus::Submit[XPHEnum::Value],$course_units));
				// if (isset($params['start_time']) && isset($params['end_time'])) {
				// 	$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				// 	$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				// }
				// $aboveeight=$this->Attend_model->get_single_full($connar1);
				// $data['ret'][$k]['aboveeight_effect']=$aboveeight['count'];


				//总分最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT max(score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['max_total_score']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				//总分最低分
				
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT min(score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['min_total_score']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';


    		            // 教学水平最高分
				/*if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT max(teaching_level_score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_level_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['max_level']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

    					// 教学水平最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT min(teaching_level_score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_level_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['min_level']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

    					// 教学效果最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT max(teaching_effect_score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_effect_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['max_effect']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

    					// 教学效果最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT min(teaching_effect_score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_effect_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$data['ret'][$k]['min_effect']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';*/
			}

			if($params['course_units'] == ''){
				$data['ret'] = array();
			}
		// 按开课教师分类
		}else if( isset($_POST['type'] ) && $_POST['type']==2){
			$where='where 1=1';
			$connar['where']=$this->sqlEscape('db_attend.status=??',array(AttendStatus::Submit[XPHEnum::Value]));
			
			 if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');
				$where.=' and db_attend.listen_time>='.strtotime($_POST['start_time']).' and db_attend.listen_time<='.strtotime($_POST['end_time'].'23:59:59');
			}	
			//课程类型
            if(isset($params['class_type'])&&$params['class_type']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.type=?? ",array($params['class_type']));
            }

            //分院名称
             if(isset($params['dept_name'])&&$params['dept_name']>-1)
            {
                $connar['where'] .= $this->sqlEscape(" and db_attend.dept_name=?? ",array($params['dept_name']));
            }

             //二级督导，校督导，外聘督导只能查看自己
            if(isset($params['teacher_code']) &&  $params['teacher_code'] != ''){
            	  $connar['where'] .= $this->sqlEscape(" and db_attend.teacher_code=?? ",array($params['teacher_code']));
            }

			if(isset($_POST['teacher_name'])){
				$connar['where'].=$this->sqlLikeEscape(" and teacher_name like '%??%'",array($_POST['teacher_name']));
				$where.=$this->sqlLikeEscape(" and teacher_name like '%??%'",array($_POST['teacher_name']));
			}

			$connar['items']=" distinct(teacher_code) ,teacher_name";
			$connar['groupby']="teacher_code";
			$connar['orderby']='listen_time desc';

			// if (!$isExport) {
			// 	$data = $this -> Attend_model -> get_page_list($connar);
			// } else {
			$count=$this->Attend_model->query('select count(*)count from (select count(*) from db_attend '.$where.' group by teacher_code) count');
			$data['count']=$count[0]['count'];
			// $data["totalPage"] = ceil($count[0]["count"] / $params['pageSize']);
			// $data['pageNo']=$params['pageNo'];
			if(isset($params['pageSize'])){
				$data["totalPage"] = ceil($count[0]["count"] / $params['pageSize']);
				$data['pageNo']=$params['pageNo'];
			}else{
				$data["totalPage"] = ceil($count[0]["count"] / 20);
				$data['pageNo']=1;
			}
			
			$data["ret"] = $this -> Attend_model -> get_list_full($connar);
			// }
			foreach ($data['ret'] as $k => $v) {
    		   //        // 被听人数
				// $course_units=str_replace ('学','分', $v['course_units']);
    		            // 分院督导听课人数 --本分院
				$connar2['items']='count(DISTINCT listen_name) unitsupervisor_num';
    					// $connar2['where']=$this->sqlEscape('db_admin.dept_name=db_attend.dept_name and db_attend.dept_name=?? and type=?? and db_attend.status=??',array($v['dept_name'],AttendType::Unit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));   
				$connar2['where']=$this->sqlEscape('db_attend.teacher_code=?? and db_attend.status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$unitsupervisor_num=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['unitsupervisor_num']=$unitsupervisor_num['unitsupervisor_num'];
    		            // 分院督导听课次数 
				$connar2['items']='COUNT(*) unitsupervisor_count';
    					// $connar2['where']=$this->sqlEscape('db_admin.dept_name=db_attend.dept_name and db_attend.dept_name=?? and type=?? and db_attend.status=??',array($v['dept_name'],AttendType::Unit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$connar2['where']=$this->sqlEscape('db_attend.teacher_code=?? and db_attend.status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$unitsupervisor_count=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['unitsupervisor_count']=$unitsupervisor_count['unitsupervisor_count'];
    		            // 校督导听课人数  
				$connar2['items']='count(DISTINCT listen_name) schoolsupervisor_num';
    					// $connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$v['dept_name'],AttendStatus::Submit[XPHEnum::Value]));
				$connar2['where']=$this->sqlEscape('db_attend.teacher_code=?? and db_attend.status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$schoolsupervisor_num=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['schoolsupervisor_num']=$schoolsupervisor_num['schoolsupervisor_num'];
    		            // 校督导听课次数  
				$connar2['items']='COUNT(*) schoolsupervisor_count';
				$connar2['where']=$this->sqlEscape('type=?? and db_attend.teacher_code=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$schoolsupervisor_count=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['schoolsupervisor_count']=$schoolsupervisor_count['schoolsupervisor_count'];

       		  // 外聘督导听课人数  
				$connar2['items']='count(DISTINCT listen_name) outsidesupervisor_num';
    					// $connar2['where']=$this->sqlEscape('type=?? and db_attend.dept_name=?? and db_attend.status=??',array(AttendType::School[XPHEnum::Value],$v['dept_name'],AttendStatus::Submit[XPHEnum::Value]));
				$connar2['where']=$this->sqlEscape('db_attend.teacher_code=?? and db_attend.status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$outsidesupervisor_num=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['outsidesupervisor_num']=$outsidesupervisor_num['outsidesupervisor_num'];
    		            // 外聘督导听课次数  
				$connar2['items']='COUNT(*) outsidesupervisor_count';
				$connar2['where']=$this->sqlEscape('type=?? and db_attend.teacher_code=?? and db_attend.status=??',array(AttendType::Outside[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar2['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
    					// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
				$outsidesupervisor_count=$this->Attend_model->get_single_full($connar2);
				$data['ret'][$k]['outsidesupervisor_count']=$outsidesupervisor_count['outsidesupervisor_count'];

				        // 总平均分          
				$connar1['items']='avg(score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_total_score']=sprintf("%.2f",$avg['avg']);

				       // 校督导总平均分          
				$connar1['items']='avg(score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_school_score']=sprintf("%.2f",$avg['avg']);


				       // 二级督导总平均分          
				$connar1['items']='avg(score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_unit_score']=sprintf("%.2f",$avg['avg']);


				       // 外聘督导总平均分          
				$connar1['items']='avg(score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=?? and type=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_outside_score']=sprintf("%.2f",$avg['avg']);


			/*	        // 教学水平平均分          
				$connar1['items']='avg(teaching_level_score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_level']=sprintf("%.2f",$avg['avg']);

    					// 教学效果平均分          
				$connar1['items']='avg(teaching_effect_score) avg';
				$connar1['where']=$this->sqlEscape('teacher_code=?? and status=??',array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=$this->sqlEscape(" and listen_time>=?? and listen_time<=??",array(strtotime($_POST['start_time']),strtotime($_POST['end_time'].'23:59:59')));
				}
				$avg=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['avg_effect']=sprintf("%.2f",$avg['avg']);
    		            // 教学水平90分(含)以上
				$connar1['items']="count(*) as count";
				$connar1['where']=$this->sqlEscape('teaching_level_score>=90 and status=??  and teacher_code=??',array(AttendStatus::Submit[XPHEnum::Value],$v['teacher_code']));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}
				$abovenine=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['abovenine_level']=$abovenine['count'];			

    					// 教学水平80以下
				$connar1['items']="count(*) as count";
				$connar1['where']=$this->sqlEscape('teaching_level_score<80 and status=??  and teacher_code=??',array(AttendStatus::Submit[XPHEnum::Value],$v['teacher_code']));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}
				$aboveeight=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['aboveeight_level']=$aboveeight['count'];

    					// 教学效果90分(含)以上
				$connar1['items']="count(*) as count";
				$connar1['where']=$this->sqlEscape('teaching_effect_score>=90 and status=??  and teacher_code=??',array(AttendStatus::Submit[XPHEnum::Value],$v['teacher_code']));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}
				$abovenine=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['abovenine_effect']=$abovenine['count'];			

    					// 教学效果80以下
				$connar1['items']="count(*) as count";
				$connar1['where']=$this->sqlEscape('teaching_effect_score<80 and status=??  and teacher_code=??',array(AttendStatus::Submit[XPHEnum::Value],$v['teacher_code']));
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$connar1['where'].=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}
				$aboveeight=$this->Attend_model->get_single_full($connar1);
				$data['ret'][$k]['aboveeight_effect']=$aboveeight['count'];*/

				//总分最高分
					if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT max(score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'listen_name'));
				$data['ret'][$k]['max_total_score']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';


				//总分最低分
				
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT min(score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				$min=$this->Attend_model->query($sql);
				$min_score=$min[0]['score'];
				$min_teacher_name=implode(',', array_column($min,'listen_name'));
				$data['ret'][$k]['min_total_score']=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';


/*
    		            // 教学水平最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT max(teaching_level_score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_level_score'];
				$max_teacher_name=implode(',', array_column($max,'listen_name'));
				$data['ret'][$k]['max_level']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

    					// 教学水平最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT min(teaching_level_score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				$min=$this->Attend_model->query($sql);
				$min_score=$min[0]['teaching_level_score'];
				$min_teacher_name=implode(',', array_column($min,'listen_name'));
				$data['ret'][$k]['min_level']=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';

    					// 教学效果最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT max(teaching_effect_score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_effect_score'];
				$max_teacher_name=implode(',', array_column($max,'listen_name'));
				$data['ret'][$k]['max_effect']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

    					// 教学效果最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT min(teaching_effect_score) from db_attend where teacher_code=??  and status=?? ".$where." ) and teacher_code=??  and status=?? ".$where." group by listen_name",array($v['teacher_code'],AttendStatus::Submit[XPHEnum::Value],$v['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));

				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT min(teaching_effect_score) from db_attend where dept_name=??  and status=?? ".$where." ) and dept_name=??  and status=?? ".$where." group by teacher_name",array($course_units,AttendStatus::Submit[XPHEnum::Value],$course_units,AttendStatus::Submit[XPHEnum::Value]));


				$min=$this->Attend_model->query($sql);
				$min_score=$min[0]['teaching_level_score'];
				$min_teacher_name=implode(',', array_column($min,'listen_name'));
				$data['ret'][$k]['min_effect']=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';*/
			}

			if($params['course_units'] == ''){
				$data['ret'] = array();
			}
		}
		


		if (!$isExport) {
			echo json_encode($data);
		} else {
            // return $data["ret"];
			// $attend_num_count=0;
			// $attend_count_count=0;
			// $unitsupervisor_num_count=0;
			// $unitsupervisor_count_count=0;
			// $schoolsupervisor_num_count=0;
			// $schoolsupervisor_count_count=0;
			// $avg_count=0;
			// $abovenine_count=0;
			// $aboveeight_count=0;
			// $max_count=0;
			// $min_count=0;
			// $connar1['items']='group_concat(teacher_name) teacher_name';
			// $connar1['where']='id in('.$maxid_all.') and status='.AttendStatus::Submit[XPHEnum::Value];
			// $max_all_name=$this->Attend_model->get_list_full($connar1);
			// $max_all_name=sprintf("%.2f",$max_all).'('.$max_all_name[0]['teacher_name'].')';
			// $connar1['items']='group_concat(teacher_name) teacher_name';
			// $connar1['where']='id in('.$minid_all.') and status='.AttendStatus::Submit[XPHEnum::Value];
			// $min_all_name=$this->Attend_model->get_list_full($connar1);
			// $min_all_name=sprintf("%.2f",$min_all).'('.$min_all_name[0]['teacher_name'].')';
			if($_POST['type']==1){
				foreach ($data['ret'] as $k => $v) {
					$data['ret'][$k]['attend_id']=$k+1;
				}
			}else{
				foreach ($data['ret'] as $k => $v) {
					$data['ret'][$k]['teacher_code']=$k+1;
				}
			}
			// var_dump($data['ret']);exit;
			// 合计
			$attend_num_unit=0;
			$attend_count_unit=0;
			$attend_num_school=0;
			$attend_count_school=0;

			$attend_num_outside=0;
			$attend_count_outside=0;

			$avg_total_score = 0;//总平均分
			$avg_school_score = 0;//校督导平均分
			$avg_unit_score = 0;//二级督导平均分
			$avg_outside_score = 0;//外聘平均分

			// $avg_level_count=0;
			// $avg_effect_count=0;
			// $abovenine_level_count=0;
			// $aboveeight_level_count=0;
			// $abovenine_effect_count=0;
			// $aboveeight_effect_count=0;
			// $max_count=0;
			// $min_count=0;
			// foreach ($data['ret'] as $k => $v) {
			// 	$attend_num_count+=$v['attend_num'];
			// 	$attend_count_count+=$v['attend_count'];
			// 	$unitsupervisor_num_count+=$v['unitsupervisor_num'];
			// 	$unitsupervisor_count_count+=$v['unitsupervisor_count'];
			// 	$schoolsupervisor_num_count+=$v['schoolsupervisor_num'];
			// 	$schoolsupervisor_count_count+=$v['schoolsupervisor_count'];
			// 	$avg_count+=$v['avg'];
			// 	$abovenine_count+=$v['abovenine'];
			// 	$aboveeight_count+=$v['aboveeight'];
			// 	$max_count+=$v['max'];
			// 	$min_count+=$v['min'];
			// }           
			// $avg_count=sprintf("%.2f",($avg_count)/count($data['ret']));
			foreach ($data['ret'] as $k => $v) {
				$attend_num_unit+=$v['unitsupervisor_num'];
				$attend_count_unit+=$v['unitsupervisor_count'];
				$attend_num_school+=$v['schoolsupervisor_num'];
				$attend_count_school+=$v['schoolsupervisor_count'];

				if(isset($_POST['type'] ) && $_POST['type']==2){
					$attend_num_outside+=$v['outsidesupervisor_num'];
					$attend_count_outside+=$v['outsidesupervisor_count'];
					$avg_total_score+=$v['avg_total_score'];
					$avg_school_score+=$v['avg_school_score'];
					$avg_unit_score+=$v['avg_unit_score'];
					$avg_outside_score+=$v['avg_outside_score'];
				}
				

				// $avg_level_count+=$v['avg_level'];
				// $avg_effect_count+=$v['avg_effect'];
				// $abovenine_level_count+=$v['abovenine_level'];
				// $aboveeight_level_count+=$v['aboveeight_level'];
				// $abovenine_effect_count+=$v['abovenine_effect'];
				// $aboveeight_effect_count+=$v['aboveeight_effect'];
			}	
			// if($avg_level_count==0 ||count($data['ret'])==0 ){
			// 	$avg_level_count=0;
			// }else{
			// 	$avg_level_count=sprintf("%.2f",($avg_level_count)/count($data['ret']));
			// }
			// if($avg_effect_count==0 ||count($data['ret'])==0 ){
			// 	$avg_effect_count=0;
			// }else{
			// 	$avg_effect_count=sprintf("%.2f",($avg_effect_count)/count($data['ret']));
			// }
			if(count($data['ret'])!=0){

				
				// 总分最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT max(score) from db_attend where  status=?? ".$where." ) and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$max_effect=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				// 总分最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where score=(SELECT min(score) from db_attend where  status=?? ".$where." ) and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$min_effect=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				// 教学水平最高分
			/*	if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT max(teaching_level_score) from db_attend where  status=?? ".$where." )  and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_level_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$max_level=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				// 教学水平最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_level_score=(SELECT min(teaching_level_score) from db_attend where  status=?? ".$where." )  and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_level_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$min_level=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				// 教学效果最高分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT max(teaching_effect_score) from db_attend where  status=?? ".$where." ) and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_effect_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$max_effect=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

				// 教学效果最低分
				if (isset($params['start_time']) && isset($params['end_time'])) {
					$where=$this->sqlEscape(' and db_attend.listen_time>=??  and db_attend.listen_time<=??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
				}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
					$where=' and db_attend.listen_time>='.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<='.strtotime($_POST['end_time']." 23:59:59");
				}else{
					$where='';
				}
				$sql=$this->sqlEscape("select * from db_attend where teaching_effect_score=(SELECT min(teaching_effect_score) from db_attend where  status=?? ".$where." ) and status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));

				$max=$this->Attend_model->query($sql);
				$max_score=$max[0]['teaching_effect_score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$min_effect=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';*/

				// array_push($data['ret'],array('title'=>'合计','attend_num_count'=>$attend_num_count,'attend_count_count'=>$attend_count_count,'unitsupervisor_num_count'=>$unitsupervisor_num_count,'unitsupervisor_count_count'=>$unitsupervisor_count_count,'schoolsupervisor_num_count'=>$schoolsupervisor_num_count,'schoolsupervisor_count_count'=>$schoolsupervisor_count_count,'avg_count'=>$avg_count,'abovenine_count'=>$abovenine_count,'aboveeight_count'=>$aboveeight_count,'max_count'=>$max_all_name,'min_count'=>$min_all_name));
				// array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>$attend_num_unit,'attend_count_unit'=>$attend_count_unit,'attend_num_school'=>$attend_num_school,'attend_count_school'=>$attend_count_school,'avg_level_count'=>$avg_level_count,'avg_effect_count'=>$avg_effect_count,'abovenine_level_count'=>$abovenine_level_count,'aboveeight_level_count'=>$aboveeight_level_count,'abovenine_effect_count'=>$abovenine_effect_count,'aboveeight_effect_count'=>$aboveeight_effect_count,'max_level'=>$max_level,'min_level'=>$min_level,'max_effect'=>$max_effect,'min_effect'=>$min_effect));
				// 
				if(isset($_POST['type'] ) && $_POST['type']==1){
					array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>$attend_num_unit,'attend_count_unit'=>$attend_count_unit,'attend_num_school'=>$attend_num_school,'attend_count_school'=>$attend_count_school,'max_effect'=>$max_effect,'min_effect'=>$min_effect));
				}

				if(isset($_POST['type'] ) && $_POST['type']==2){
					array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>$attend_num_unit,'attend_count_unit'=>$attend_count_unit,'attend_num_school'=>$attend_num_school,'attend_count_school'=>$attend_count_school,'attend_num_outside'=>$attend_num_outside,'attend_count_outside'=>$attend_count_outside,'avg_total_score'=>$avg_total_score,'avg_school_score'=>$avg_school_score,'avg_unit_score'=>$avg_unit_score,'avg_outside_score'=>$avg_outside_score,'max_effect'=>$max_effect,'min_effect'=>$min_effect));
				}
			

			}else{
				// array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>0,'attend_count_unit'=>0,'attend_num_school'=>0,'attend_count_school'=>0,'avg_level_count'=>0,'avg_effect_count'=>0,'abovenine_level_count'=>0,'aboveeight_level_count'=>0,'abovenine_effect_count'=>0,'aboveeight_effect_count'=>0,'max_level'=>0,'min_level'=>0,'max_effect'=>0,'min_effect'=>0));
				if(isset($_POST['type'] ) && $_POST['type']==1){
					array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>0,'attend_count_unit'=>0,'attend_num_school'=>0,'attend_count_school'=>0,'max_effect'=>0,'min_effect'=>0));
				} 
				if(isset($_POST['type'] ) && $_POST['type']==2){
					array_push($data['ret'],array('title'=>'合计',''=>'','attend_num_unit'=>0,'attend_count_unit'=>0,'attend_num_school'=>0,'attend_count_school'=>0,'attend_num_outside'=>0,'attend_count_outside'=>0,'avg_total_score'=>0,'avg_school_score'=>0,'avg_unit_score'=>0,'avg_outside_score'=>0,'max_effect'=>0,'min_effect'=>0));
				} 
				
				
			}

			$this-> load ->library('PHPExcel/PHPExcel');
			$excel = new PHPExcel();
            //公共样式
			$excel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(11); 
			$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setWrapText(true);
			$excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(23);
			$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$excel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

			$x_line=0;
			$y_line=1;

            //标题
			// $title=array($_POST['start_time'].'至'.$_POST['end_time'],'被听人数','被听人次','分院督导听课人数','分院督导听课次数','校督导听课人数','校督导听课次数','平均分','90分(含)以上','80分以下','最高分','最低分');
			if($_POST['type']==1){
				$group='开课单位';
			}else{
				$group='教师姓名';
			}

			if(isset($_POST['type'] ) && $_POST['type']==1){
				$title=array($_POST['start_time'].'至'.$_POST['end_time'],$group,'督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','总分最高分','总分最低分');
			}else if(isset($_POST['type'] ) && $_POST['type']==2){
				$title=array($_POST['start_time'].'至'.$_POST['end_time'],$group,'督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','外聘督导听课人数','外聘督导听课次数','总分平均分','校督导平均分','二级督导平均分','外聘督导平均分','总分最高分','总分最低分');
			}
			
			foreach ($title as $k => $v) {
				$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v);
				$excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line)->getFont()->setBold(true);   
				$x_line++;
			}

			$x_line=0;
			$y_line=2;
            //正式数据
			
			foreach ($data['ret'] as $k => $v) {            
				foreach ($v as $k1 => $v1) {
                    // if($k1=='id'){
                    //  $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$_POST['start_time'].'至'.$_POST['end_time']);
                    // }else{
					if($k1=='id'){
						continue;
					}
					$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v1);
                    // }
                    // }
					
					$x_line++;
				}
				$x_line=0;
				$y_line++;
			}


			pri($data['ret']);
			$write = new PHPExcel_Writer_Excel2007($excel); 
			$director = "upload/export/" . date('Ymd', time()) . "/";
			if (!file_exists($director)) {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
				mkdir($director, 0777);
			}        
			$file_name ='听课数据分析表'.date('Ymd').'.xlsx';          
			$write->save($director.iconv('utf-8', 'gb2312', $file_name));
			//exit(retJson('返回地址',true,$director.$file_name));
		}
	}


	// 获取被听课教师列表
	/**
	 * @param course_units 开课单位
	 * @param start_time 开始时间
	 * @param end_time 结束时间
	 */
	function getTeacherList($select,$type,$course_units,$source,$start_time=false,$end_time=false,$isExport=false){

	   if($isExport){//是否导出
			$select = $_POST['select'];
			$type = $_POST['type'];
			$course_units = $_POST['course_units'];
			$start_time = $_POST['start_time'];
			$end_time = $_POST['end_time'];
		}

		$course_units=urldecode($course_units);
		$course_units=str_replace ('学','分', $course_units);
		if($start_time){
			$start_time=strtotime(urldecode($start_time)) ;
		}
		if($end_time){
			$end_time=strtotime(urldecode($end_time));
		}	

		if($select=='1'){
			$connar['where']=$this->sqlEscape("status=?? and dept_name=?? ",array(AttendStatus::Submit[XPHEnum::Value],$course_units));
			$connar['orderby']="teacher_name";
			if($type==1){
				$connar['items']="teacher_name,teacher_code,score";	
				$connar['where'].=$this->sqlEscape("and type=??",array(AttendType::Unit[XPHEnum::Value]));
			}else if($type==2){
				$connar['items']="teacher_name,teacher_code,score";	
				$connar['where'].=$this->sqlEscape("and type=??",array(AttendType::School[XPHEnum::Value]));
			}else if($type==3){
				$connar['where'].=$this->sqlEscape("and teaching_level_score>=90",array());
			}else if($type==4){
				$connar['where'].=$this->sqlEscape("and teaching_level_score<80",array());
			}else if($type==5){
				$connar['where'].=$this->sqlEscape("and teaching_effect_score>=90",array());
			}else if($type==6){
				$connar['where'].=$this->sqlEscape("and teaching_effect_score<80",array());
			}
		}else{
			$connar['where']=$this->sqlEscape("db_attend.status=?? and teacher_code=?? ",array(AttendStatus::Submit[XPHEnum::Value],$course_units));
			$connar['orderby']="listen_id";
			$connar['join']=array('db_admin','db_admin.id=db_attend.listen_id');
			$connar['items']="listen_name teacher_name,usercode as teacher_code";			
			if($type==1){	
				$connar['items']="DISTINCT (listen_name) teacher_name,usercode as teacher_code,db_attend.score score";				
				$connar['where'].=$this->sqlEscape("and type=??",array(AttendType::Unit[XPHEnum::Value]));
			}else if($type==2){
				$connar['items']="DISTINCT (listen_name) teacher_name,usercode as teacher_code,db_attend.score score";
				$connar['where'].=$this->sqlEscape("and type=??",array(AttendType::School[XPHEnum::Value]));
			}else if($type==3){
				$connar['where'].=$this->sqlEscape("and teaching_level_score>=90",array());
			}else if($type==4){
				$connar['where'].=$this->sqlEscape("and teaching_level_score<80",array());
			}else if($type==5){
				$connar['where'].=$this->sqlEscape("and teaching_effect_score>=90",array());
			}else if($type==6){
				$connar['where'].=$this->sqlEscape("and teaching_effect_score<80",array());
			}
		}
		
		
		// $connar['join']=array('db_admin','db_admin.id=db_')
		
		// if (isset($params['start_time']) && isset($params['end_time'])) {
		// 	$where.=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
		// }else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
		// 	$where.=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
		// }
		if($start_time){
			$connar['where'].=$this->sqlEscape(' and listen_time>??',array($start_time.' 00:00:00'));
		}
		if($end_time){
			$connar['where'].=$this->sqlEscape(' and listen_time<??',array($end_time." 23:59:59"));
		}
		$data['list']=$this->Attend_model->get_list_full($connar);

		if($type==1){
			$data['title']="分院督导听课次数";
		}else if($type==2){
			$data['title']="校督导听课次数";
		}else if($type==3){
			$data['title']="教学水平90分(含)以上";
		}else if($type==4){
			$data['title']="教学水平80以下";
		}else if($type==5){
			$data['title']="教学效果90分(含)以上";
		}else if($type==6){
			$data['title']="教学效果80以下";
		}

		//导出
	   if($isExport){

		   $this-> load ->library('PHPExcel/PHPExcel');
            $excel = new PHPExcel();
            //公共样式
            $excel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(11); 
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setWrapText(true);
            $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(23);
            $excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $excel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

            $x_line=0;
            $y_line=1;

            //正式开始
            $excel = new PHPExcel();
            $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(15);

              //标题
            $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0).'1:'.PHPExcel_Cell::stringFromColumnIndex(4).'1');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).'1',$data['title']);
            $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
            $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
            $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $i=2;
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,'序号');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,'工号');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,'姓名');
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,'总分');
              
        $i++;
        foreach ($data['list'] as $k => $v) {
           
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$i,$k+1);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$i,$v['teacher_code']);
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$i,$v['teacher_name']); 
            $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$i,$v['score']);           
            $i++;
        }
        //设置对齐
        $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(9).($i-1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $excel->getActiveSheet()->getStyle('A1:'.PHPExcel_Cell::stringFromColumnIndex(0).($i-1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);


            $write = new PHPExcel_Writer_Excel2007($excel); 
            $director = "upload/export/" . date('Ymd', time()) . "/";
            if (!file_exists($director)) {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                mkdir($director, 0777);
            }        
            $file_name =$data['title'].date('Ymd').'.xlsx';           
            $write->save($director.iconv('utf-8', 'gb2312', $file_name));
            exit(retJson('返回地址',true,$director.$file_name));

	   }else{
	  	 	$data['params'] = array('select'=>$select,'source'=>$source,'type'=>$type,'course_units'=>$course_units,'start_time'=>$start_time,'end_time'=>$end_time);
	   	    $this->load->view('admin/attendDept',$data);
	   }

	}
	


}



